/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Eliminar_Item.java
 *
 * Created on 25-feb-2011, 9:57:47
 */

package puntoventa;

import java.sql.*;
import javax.swing.JOptionPane;

/**
 *
 * @author gadiaz3
 */
public class Eliminar_Item extends javax.swing.JFrame {

    /** Creates new form Eliminar_Item */
    public Eliminar_Item() {
        initComponents();
        this.setLocationRelativeTo(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        FID = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        VolverB = new javax.swing.JButton();
        ConfirmB = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Lucida Grande", 0, 12));
        jLabel1.setText("Ingrese el ID del producto.");

        jLabel2.setText("ID:");

        jLabel3.setBackground(new java.awt.Color(252, 254, 223));
        jLabel3.setFont(new java.awt.Font("Lucida Grande", 0, 18));
        jLabel3.setText("Eliminar Articulo");

        VolverB.setText("Volver");
        VolverB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                VolverBActionPerformed(evt);
            }
        });

        ConfirmB.setText("Confirmar");
        ConfirmB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ConfirmBActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jLabel2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(FID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 179, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jLabel1)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(VolverB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 109, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 42, Short.MAX_VALUE)
                        .add(ConfirmB))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 115, Short.MAX_VALUE)
                        .add(jLabel3)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel3)
                .add(18, 18, 18)
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(FID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(VolverB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 43, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(ConfirmB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 43, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void VolverBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_VolverBActionPerformed
        Administrador Admin = new Administrador();
        Admin.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_VolverBActionPerformed

    private void ConfirmBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ConfirmBActionPerformed
        String ID = FID.getText();

        if (FID.getText().compareTo("") == 0) {
            JOptionPane.showMessageDialog(null, "Debe especificar el [ID] para eliminar.", "Atencion", JOptionPane.INFORMATION_MESSAGE);
        } else
            try {

            Connection c = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/PDV", "root", "root");
            Statement sql = (Statement) c.createStatement();


            sql.executeUpdate("delete from Productos where ID=" + ID + "");

            JOptionPane.showMessageDialog(null, "Producto [" + ID + "] Borrado!", "Atencion", JOptionPane.INFORMATION_MESSAGE);

            FID.setText("");
            //JOptionPane.showConfirmDialog(null, "¿Está seguro que desea eliminar el articulo " + ID +" y toda su información?", "Atención!", JOptionPane.YES_OPTION);

        } catch (SQLException ex) {

            ex.printStackTrace();
        }

    }//GEN-LAST:event_ConfirmBActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Eliminar_Item().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ConfirmB;
    private javax.swing.JTextField FID;
    private javax.swing.JButton VolverB;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration//GEN-END:variables

}
